#include "TitleCompositeNode.h"

#include "../Logger.h"

StatusBar* TitleCompositeNode::addBar(irr::core::stringw name, e_barType type) {
	core::stringw clsname = L"TitleCompositeNode";
	core::stringw msg;
	if(!m_containedNodes[name]) {
		msg = (core::stringw(L"addBar ")+name+core::stringw(L" not allocated."));
		Facets::Logger::Instance()->log(clsname.c_str(),msg.c_str(),irr::ELL_INFORMATION);
		m_containedNodes[name] = new StatusBar(this,(m_containedNodes.size())*7.5f,SceneManager);
		msg = name+core::stringw(L" is created.");
		Facets::Logger::Instance()->log(clsname.c_str(),msg.c_str(),irr::ELL_INFORMATION);		
		dynamic_cast<StatusBar*>(m_containedNodes[name])->updatePercent(100.0f);
	} else {
		msg = core::stringw(L"addBar ")+name+core::stringw(L" exists.");
		Facets::Logger::Instance()->log(clsname.c_str(),msg.c_str(),irr::ELL_INFORMATION);
		delete m_containedNodes[name];
		msg = name+core::stringw(L" deleted.");
		Facets::Logger::Instance()->log(clsname.c_str(),msg.c_str(),irr::ELL_INFORMATION);		
		m_containedNodes[name] = new StatusBar(this,(m_containedNodes.size())*7.5f,SceneManager);
		msg = name+core::stringw(L" is created.");
		Facets::Logger::Instance()->log(clsname.c_str(),msg.c_str(),irr::ELL_INFORMATION);		
		dynamic_cast<StatusBar*>(m_containedNodes[name])->updatePercent(100.0f);
	}
}

LabelNode* TitleCompositeNode::addLabel(irr::core::stringw stringRef, irr::core::stringw stringName) {
	if(!m_containedNodes[stringRef]) {
		m_containedNodes[stringRef] = new LabelNode(this,stringName,(m_containedNodes.size())*7.5f,SceneManager);
	} else {
		delete m_containedNodes[stringRef];
		m_containedNodes[stringRef] = new LabelNode(this,stringName,(m_containedNodes.size())*7.5f,SceneManager);		
	}
}

void TitleCompositeNode::render() {
    std::map<irr::core::stringw, ContainedNode*>::const_iterator iter;
    for (iter = m_containedNodes.begin(); iter != m_containedNodes.end(); ++iter) {
    	iter->second->updateLocation();
    }	
}
